package com.sk.weichat.ui.base;

import android.Manifest;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import com.sk.weichat.R;
import com.sk.weichat.ui.SplashActivity;
import com.sk.weichat.util.PermissionUtil;

import java.util.List;

public abstract class BaseActivity extends BaseLoginActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 竖屏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//亮色主题状态栏(黑字)
            this.getWindow().getDecorView()
                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        //在设置中修改权限，返回应用崩溃
        if (savedInstanceState != null) {
            List<String> permissionList = PermissionUtil.getDeniedPermissions(this,
                    new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE});

            //SplashActivity自身不需要跳转
            if (permissionList != null && !(this instanceof SplashActivity)) {
                Intent intent = new Intent(this, SplashActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return;
            }

        }
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
    }

}
